import {
  queryEntityTypes, queryByTypeCode, queryEntityIdsByTypeCode
} from '@/api/authEntity'

const getDefaultState = () => {
  return {

  }
}

const state = getDefaultState()

const mutations = {

}

const actions = {
  /**
   * 查询当前租户权限
   */
  getEntityTypes() {
    return new Promise(function (resolve, reject) {
      queryEntityTypes().then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 通过权限实体类型获取权限实体
   */
  getByTypeCode({ commit }, typeCode) {
    return new Promise(function (resolve, reject) {
      queryByTypeCode(typeCode).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 通过类型编码获取权限实体id
   */
  getEntityIdsByTypeCode({ commit }, typeCode) {
    return new Promise(function (resolve, reject) {
      queryEntityIdsByTypeCode(typeCode).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
